package com.holyn.guofang.zxing.utils;

import com.android.volley.AuthFailureError;
import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.holyn.guofang.MyApplication;
import com.holyn.guofang.model.webhttp.HttpConfigure;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018-05-14.
 */

public class ZxingRESTFul {

    public interface IhttpCb{
        public void ok(JSONObject response);
        public void error(String error);
    }

    public static String api = "submitQrCode";

    public ZxingRESTFul() {

    }
    public void get(String qrID,String devID,String nonce,String signCode,int platformType,int timestamp,final IhttpCb cb) {
//        String url = HttpConfigure.BASE_URL + api;
        String url = HttpConfigure.BASE_URL+"SubmitQrCodeb.ashx?QrID="+qrID+"&DevID="+devID+"&Nonce="+nonce+"&Timestamp="+timestamp+"&PlatformType="+platformType+"&SignCode="+signCode;
        JsonObjectRequest getCurrentUser = new JsonObjectRequest(Request.Method.GET, url, null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        cb.ok(response);
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        error.printStackTrace();
                        if (cb!=null) {
                            cb.error(error.toString());
                        }
                    }
                }
        ){


            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
                return headers;
            }
        };
        MyApplication.requestQueue.add(getCurrentUser);
    }
}
